﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<%@ Register assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" namespace="CrystalDecisions.Web" tagprefix="CR" %>

<!DOCTYPE html>

<html>
<head runat="server">
    <title>frmLstPer</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            System.Data.DataTable dtLstCanBo = MakeTable();
            List<QLNS.CanBo> lstCanBo = QLNS.Models.CanBoModels.GetDSCanBo();
            foreach (var r in lstCanBo)
            {
                System.Data.DataRow row;
                row = dtLstCanBo.NewRow();
                row["ID"] = r.ID;
                row["SoHieuCBCC"] = r.SoHieuCBCC;
                row["Ho"] = r.Ho;
                row["Ten"] = r.Ten;
                dtLstCanBo.Rows.Add(row);
            }

            CrystalDecisions.CrystalReports.Engine.ReportDocument rd = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
            string strRptPath = Server.MapPath("~/") + "Reports//crLstPer.rpt";
            //Loading Report
            rd.Load(strRptPath);

            // Setting report data source
            if (dtLstCanBo != null && dtLstCanBo.GetType().ToString() != "System.String")
                rd.SetDataSource(dtLstCanBo);


            CrystalReportViewer1.ReportSource = rd;
            this.Label1.Text = ViewBag.dept;
        }
        private System.Data.DataTable MakeTable()
        {
            // Create a new DataTable.
            System.Data.DataTable table = new System.Data.DataTable("Table");

            // Declare variables for DataColumn and DataRow objects.
            System.Data.DataColumn column;

            // Create new DataColumn, set DataType, 
            // ColumnName and add to DataTable.    
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "ID";
            column.Unique = true;
            // Add the Column to the DataColumnCollection.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "SoHieuCBCC";
            column.Caption = "So Hieu can bo";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "Ho";
            column.Caption = "Hoj";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "Ten";
            column.Caption = "teen";
            // Add the column to the table.
            table.Columns.Add(column);



            // Make the ID column the primary key column.
            System.Data.DataColumn[] PrimaryKeyColumns = new System.Data.DataColumn[1];
            PrimaryKeyColumns[0] = table.Columns["ID"];
            table.PrimaryKey = PrimaryKeyColumns;
            return table;
        }
</script>
        <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" 
            AutoDataBind="true" ToolPanelView="None" />
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </div>
    </form>
</body>
</html>
